﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LightSwitchApplication.UserCode
{
    public class MyImageHelper
    {
        public static byte[] GetImageByName(string filename)
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

            System.IO.Stream stream = assembly.GetManifestResourceStream(typeof(LightSwitchApplication.PatientDetail).Namespace +
                ".Resources." + filename);

            return GetStreamAsByteArray(stream);
        }

        private static byte[] GetStreamAsByteArray(System.IO.Stream stream)
        {
            if (stream != null)
            {

                int streamLength = Convert.ToInt32(stream.Length);

                byte[] fileData = new byte[streamLength];

                stream.Read(fileData, 0, streamLength);

                stream.Close();

                return fileData;
            }
            else
                return null;

        }
    }
}
